﻿<%@ Page Language="C#" MasterPageFile="~/Site.master"  AutoEventWireup="true" CodeBehind="Voorpagina.aspx.cs" Inherits="WebshopPizzaRio.Voorpagina" ValidateRequest="false" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PizzaRioConnectionString %>" 
        SelectCommand="SELECT text FROM voorpagina where voorpaginaid = 1">
    </asp:SqlDataSource>

    <h1>Voorpagina</h1>

    <asp:LoginView ID="LoginView1" runat="server">

        <AnonymousTemplate>
            <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1">

        <LayoutTemplate>
            <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
        </LayoutTemplate>
        <ItemTemplate>
                <%#Eval("text") %>
        </ItemTemplate>
    </asp:ListView>

        </AnonymousTemplate>

        <LoggedInTemplate>
           <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1">

        <LayoutTemplate>
            <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
        </LayoutTemplate>
        <ItemTemplate>
                <%#Eval("text") %>
        </ItemTemplate>
    </asp:ListView>
        </LoggedInTemplate>


        <RoleGroups>

            <asp:RoleGroup Roles="Administrators">
                <ContentTemplate>
                    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:PizzaRioConnectionString %>" 
        DeleteCommand="DELETE FROM [voorpagina] WHERE [voorpaginaid] = @voorpaginaid" 
        InsertCommand="INSERT INTO [voorpagina] ([voorpaginaid], [text]) VALUES (@voorpaginaid, @text)" 
        SelectCommand="SELECT [voorpaginaid], [text] FROM [voorpagina]" 
        UpdateCommand="UPDATE [voorpagina] SET [text] = @text WHERE [voorpaginaid] = @voorpaginaid">
        <DeleteParameters>
            <asp:Parameter Name="voorpaginaid" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="voorpaginaid" Type="Int32" />
            <asp:Parameter Name="text" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="text" Type="String" />
            <asp:Parameter Name="voorpaginaid" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="voorpaginaid" 
        DataSourceID="SqlDataSource2">
        <EditItemTemplate>
            <asp:TextBox ID="textTextBox" runat="server" Text='<%# Bind("text") %>' TextMode="multiline" />
            <br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="False" 
                CommandName="Update" Text="Update" />
            &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                CausesValidation="False" CommandName="Cancel" Text="Annuleren" />
                <br /><br />

                <asp:CustomValidator ID="valFile" runat="server" 
            ErrorMessage="Geen bestand geüpload." 
            onservervalidate="valFile_ServerValidate" Display="Dynamic" ForeColor="Red" />
        <asp:CustomValidator ID="valFileType" runat="server" 
            ErrorMessage="Dit is geen afbeelding." 
            onservervalidate="valFileType_ServerValidate" Display="Dynamic" ForeColor="Red" />
        <asp:CustomValidator ID="valFileSize" runat="server" 
            ErrorMessage="Deze afbeelding is groter dan 10MB." 
            onservervalidate="valFileSize_ServerValidate" Display="Dynamic" ForeColor="Red" /><br />
            <p>Afbeelding toevoegen:</p>
                <asp:FileUpload ID="fileImage" runat="server" />
            
        <asp:Button ID="btnSubmit" runat="server" Text="Upload" 
            onclick="btnSubmit_Click" />
            <br /><br />
            <asp:Label ID="Label2" runat="server" Text="Kopieer uw code: " Visible="False"></asp:Label>
            <br />
            <asp:Label ID="Label1" runat="server" Text="Label" Visible="False" ForeColor="Red" ></asp:Label>

        </EditItemTemplate>
        <ItemTemplate>
            <asp:Label ID="textLabel" runat="server" Text='<%# Bind("text") %>' />
            <br />
            <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" 
                CommandName="Edit" Text="Bewerken" />
        </ItemTemplate>
    </asp:FormView>
                </ContentTemplate>
            </asp:RoleGroup>

        </RoleGroups>

    </asp:LoginView>

</asp:Content>

